<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .active{
            background: red;
        }
    </style>
</head>
<body>
<input id="txt" type="text">
<button id="btn">搜索</button>
<br/><br/>
<table width="500" border="1" style="border-collapse: collapse">
    <thead>
        <th>编号</th>
        <th>名字</th>
        <th>年龄</th>
        <th>操作</th>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>张三</td>
            <td>10</td>
            <td><a>删除</a></td>
        </tr>
        <tr>
            <td>2</td>
            <td>李四</td>
            <td>11</td>
            <td><a>删除</a></td>
        </tr>
        <tr>
            <td>3</td>
            <td>张四</td>
            <td>12</td>
            <td><a>删除</a></td>
        </tr>
        <tr>
            <td>4</td>
            <td>王五</td>
            <td>13</td>
            <td><a>删除</a></td>
        </tr>
        <tr>
            <td>5</td>
            <td>Bucky</td>
            <td>10</td>
            <td>
                <a>删除</a>
            </td>
        </tr>
    </tbody>
</table>
<script>
    var oBtn = document.getElementById('btn');
    var oTxt = document.getElementById('txt');
    var oTable = document.getElementsByTagName('table')[0];
    var aRows = oTable.tBodies[0].rows;


    //方法一：indexof
   /* oBtn.onclick = function () {
        for(var i=0;i<aRows.length;i++){

            var sTab = aRows[i].cells[1].innerHTML;
            var sTxt = oTxt['value'];

            if(sTab.indexOf(sTxt)>-1){
                aRows[i].style.background = 'red';
            }
            else {
                aRows[i].style.background = '';
            }

        }
    }*/


    //方法二：search
    oBtn.onclick = function () {
       for(var i=0;i<aRows.length;i++){
           var sTab = aRows[i].cells[1].innerHTML.toLocaleLowerCase();
           var sTxt = oTxt['value'].toLocaleLowerCase();

           var aTxt = sTxt.split('');
           for(var j=0;j<aTxt.length;j++){
               if(sTab.search(aTxt[j])!=-1){
                   aRows[i].style.background = 'red';
               }
           }


       }
    }



















</script>
</body>
</html>